/**
Author: Maciej Oczko
Date: November 2011
*/

#ifndef POOLGROUPMANAGER_H_
#define POOLGROUPMANAGER_H_
#include <vector>
#include "PoolMemoryManager.h"

class PoolGroupManager
{
private:
	/// Vector of pools.
	std::vector<PoolMemoryManager *> m_Pools;
	/// Vector of offsets to ids.
	std::vector<unsigned > m_Offsets;

	PoolGroupManager(const PoolGroupManager&);
	PoolGroupManager & operator=(const PoolGroupManager &);

	/// Adds proper offset to offsets vector.
	void AddOffset(unsigned p_Capacity);
public:
	PoolGroupManager();
	~PoolGroupManager();
	/// Adds new pool to pools vector.
	void AddNewPool(unsigned p_ElementSize, unsigned m_Capacity);
	/// Adds existing pool to pools vector.
	void AddExistingPool(PoolMemoryManager *p_pmm);
	/// Frees all pools.
	void FreePools();

	/// Returns new instance of memory element from pool which size of element fits best.
	void * New(unsigned p_ElementSize);
	/// Returns new instance of memory element from pool which size of element fits best and id.
	void * New(unsigned p_ElementSize, unsigned &p_Id);
	/// Reclaims the instance referenced by p_Instance.
	void Delete(void *p_Instance);
	/// Reclaims the instance referenced by p_Id.
	bool Delete(unsigned p_Id);

	/// Returns size of the pools vector.
	inline unsigned GetSize() const { return m_Pools.size(); }
};

#endif